<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/admin/lib/html5shiv.js"></script>
    <script type="text/javascript" src="/admin/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui/css/H-ui.css"/>
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="/admin/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="/admin/lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <script>
        var olddate = null;
        function ChangeValue() {
            if(olddate !== $(this).val()){
                $('#emptyw').trigger('click');
            }
        }
        function nowValue() {
            olddate = $(this).val();
        }
    </script>
    <title></title>
</head>
<body>
<div class="hide">
    {{$b_batchNum = request()->get('b_batchNum','') }}
</div>
<nav class="breadcrumb">
    @if($b_batchNum)
        <i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 检测业务 <span class="c-gray en">&gt;</span>
        <a href="javascript:;" onclick="location.href='/{{config('constant.name_admin')}}/contract/viewAllBatch';">全部批次</a>
        <span class="c-gray en">&gt;</span> 查看试验台账
        <a class="btn btn-primary radius r mt-10" href="javascript:self.location=document.referrer;">
            <i class="Hui-iconfont Hui-iconfont-arrow1-left"></i>&nbsp;&nbsp;返回
        </a>
        @else
    <i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 检测业务 <span class="c-gray en">&gt;</span>
        试验台账
        <a class="btn btn-primary radius f-r" style="line-height:1.6em;margin-top:3px"
           href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
    @endif

</nav>
<div class="cl pd-5 bg-1 bk-gray ml-10">
    <form id="exportform">
        <span class="l">
            <a class="btn btn-primary radius" onclick="download_excel(0,this)" target="_blank">导出近半年数据</a>
            <a onclick="download_excel(1,this)" class="btn btn-primary radius" target="_blank">导出筛选后的数据</a>
            <input class="ml-20" type="checkbox" name="export_nonphoto" value="1">导出不合格照片
            <input class="ml-20" type="checkbox" name="export_photo" value="1">导出斗臂车铭牌照片
            <input class="ml-20" type="checkbox" name="export_erweima" value="1">导出二维码
        </span>
    </form>
</div>
<form class="form-horizontal ml-20" action="" id="paramform" onsubmit="return false;">
    <div class="form-group ml-50 mt-10"> 检测日期范围：
        <div class="hidden">{{$year = date('Y')}}</div>
        <select onchange="changedate()" id="year" class=" inline input-text" id="month">
            <option value="">年份选择</option>
            @for($i=2017;$i<$year;$i++)
                <option value="{{$i+1}}">{{$i+1}}</option>
            @endfor
        </select>
        <select onchange="changedate()" class=" inline input-text" id="month">
            <option value="">月份选择</option>
            @for($i=1;$i<13;$i++)
                <option value="{{$i}}">{{$i}}月</option>
            @endfor
        </select>
        <select onchange="changedate()" class="inline input-text" id="week">
            <option value="">周选择</option>
            @for($i=1;$i<6;$i++)
                <option value="{{$i}}">第{{$i}}周</option>
            @endfor
        </select>
        <input id="emptyw" type="button" class="btn btn-primary-outline size-S" value="清空">
        <input type="text" autocomplete="off" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}',onpicked:ChangeValue,onpicking: nowValue })" name="test_time_0" id="datemin" class="input-text Wdate ml-50" style="width:120px;" value="" placeholder="开始时间">
        -
        <input type="text" autocomplete="off" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d' ,onpicked:ChangeValue,onpicking: nowValue})" name="test_time_1" id="datemax" class="input-text Wdate" style="width:120px;" value="" placeholder="结束时间">
        <input id="emptydate" type="button" class="btn btn-primary-outline size-S ml-50" value="清空">
    </div>
    <br>
    <div class="form-group ml-50 mt-10"> 检测地点：
        <input type="text" name="place" class="input-text" style="width:120px;" value="">
    </div>
    <div class="form-group ml-50 mt-10"> 委托单位：
        <input type="text" name="b_entrusted_company" class="input-text" style="width:120px;" value="">
    </div>
    <div class="form-group ml-50 mt-10"> 批次号：
        <input type="text" name="b_batchNum" class="input-text" style="width:120px;" value="{{$b_batchNum}}">
    </div>
    <div class="form-group ml-50 mt-10"> 条形码：
        <input type="text" name="bar_code" class="input-text" style="width:120px;" value="">
    </div>
    <div class="form-group ml-50 mt-10"> 物资名称：
        <input type="text" name="c_tool_name" class="input-text" style="width:120px;" value="">
    </div>
    <div class="form-group ml-50 mt-10">检测结果：
        <select class="inline input-text" name="res">
            <option value="">请选择</option>
            <option value="0">未检测</option>
            <option value="1">合格</option>
            <option value="2">不合格</option>
        </select>
    </div>
    <div class="form-group ml-50 mt-10">原始条码：
        <input type="text" name="bar_code_1st" class="input-text" style="width:120px;" value="">
    </div>
    <button onclick="searchDate()" class="btn btn-success radius ml-20 mt-10">
        <i class="Hui-iconfont">&#xe665;</i> 查询
    </button>
</form>
<div class="page-container">
    <div class="hidden" id="report_num_pre">{{$data['report_num_pre']}}</div>
    <table class="table table-border table-bordered table-bg table-hover table-condensed table-responsive"
           id="datatable" style="white-space: nowrap;">
        <thead>
        <tr class="text-c">
{{--            <th><input type="checkbox"></th>--}}
            <th>检测年度</th>
            <th>检测周次</th>
            <th>检测地点</th>
            <th>委托单位</th>
            <th>批次号</th>
            <th>条形码</th>
            <th>额定电压</th>
            <th>物资名称</th>
            <th>物资分类</th>
            <th>物资型号</th>
            <th>分类</th>
            <th>试验数量</th>
            <th>计量单位</th>
            <th>样品自编号</th>
            <th>商标</th>
            <th>生产日期</th>
            <th>生产厂家</th>
            <th>检测标准</th>
            <th>试验项目</th>
            <th>试验时间</th>
            <th>检测结果</th>
            <th>不合格项目</th>
            <th>有效期</th>
            <th>报告编号</th>
            <th>铭牌照片</th>
            <th>不合格照片</th>
            <th>二维码</th>
            <th>检测费用（元）</th>
            <th>支付时间</th>
            <th>支付状态</th>
            <th>付款合同编号</th>
            <th>备注</th>
            <th>联系人</th>
            <th>联系电话</th>
        </tr>
        </thead>
        <tbody class="text-c"></tbody>
    </table>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/admin/lib/layer/3.1.1/layer.js"></script>
<script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/admin/lib/qrcode.min.js"></script>
<script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/admin/lib/jquery.mousewheel.min.js"></script>
<script type="text/javascript"
        src="/admin/static/myfolder/js/imgopreate.js?ver={{config('constant.static_res_ver')}}"></script>
<script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/admin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script>
    $('#emptydate').click(function () {
        $('#datemin').val('');$('#datemax').val('');
    });
    var params = null;
    $.fn.dataTable.ext.errMode = 'throw';//datatable抛异常的方式，在console中输出，默认以alert的方式弹出
    var table = $('#datatable').DataTable({
        pageLength: 25,
        scrollY: 600,
        scrollX: true,
        serverSide: true,
        ajax: {
            url: 'list',
            method:'post',
            data: function ( d ) {
                d.searcho = $('#paramform').serializeArray();
                d._token = '{{csrf_token()}}';
                // console.log(d);
            }
        },
        columns: [
            // {
            //     data: null, render: function (data, type, row, meta) {
            //         return "<input type='checkbox' value='" + row.id + "'>";
            //     }, searchable: false, orderable: false
            // },
            {
                data: "test_time", render: function (data) {
                    return data !== null ? new Date(Date.parse(data)).Format("yyyy") : '';
                },searchable:false
            },
            {
                data: "test_time", render: function (data) {
                    if(data !== null){
                        let month = new Date(Date.parse(data)).Format("MM");
                        let day = new Date(Date.parse(data)).Format("dd");
                        let weekth = Math.ceil(day / 7);
                        return month + '月第' + weekth + '周';
                    }else{
                        return '';
                    }
                },searchable:false,orderable: false
            },
            {data: "place"},
            {data: "b_entrusted_company",searchable:false,orderable: false},
            {data: "b_batchNum",searchable:false,orderable: false},
            {data: "bar_code",searchable:false,orderable: false},
            {data: "c_voltage"},
            {data: "c_tool_name"},
            {data: "e_name"},
            {data: "guige_xinghao"},
            {data: "c_class"},
            {
                data: null, render: function () {
                    return 1;
                }, searchable: false, orderable: false
            },
            {data: "c_unit"},
            {data: "self_num"},
            {data: "brand"},
            {data: "production_date"},
            {data: "manufacturer"},
            {data: "c_std_num"},
            {data: "c_item_names",render:function (data) {
                let str = '<span title="';
                let data1 = data.length > 20 ?  data.substring(0,20) + '...'　: data;
                str += data + '">'+ data1 + '</span>';
                return str;
            },orderable: false},
            {data: "test_time"},
            {
                data: "res", render: function (data) {
                    return data == 1 ? '合格' : data == 2 ? '不合格' : '未检测';
                }
            },
            {data: "g_name"},
            {data: "next_time"},
            {
                data: null, render: function (data, type, row, meta) {
                    return $('#report_num_pre').text() + row.b_batchNum;
                }, searchable: false, orderable: false
            },
            {
                data: 'photo', render: function (data, type, row, meta) {
                    let str = '<div style="width:120px;">';
                    str += data === '' ? '/' : '<img onclick="biggerimg(this)" class="img-responsive" style="width: 100px;" src="' + data + '" alt="">';
                    str += '</div>';
                    return str;
                }, searchable: false, orderable: false
            },
            {
                data: 'non_photo', render: function (data, type, row, meta) {
                    let str = '<div style="width:120px;">';
                    str += data === '' ? '/' : '<img onclick="biggerimg(this)" class="img-responsive" style="width: 100px;" src="' + data + '" alt="">';
                    str += '</div>';
                    return str;
                }, searchable: false, orderable: false
            },
            {
                data: null, render: function (data, type, row, meta) {
                    return '<div class="box-qrcode" key="' + row.key + '" id="qrcode-' + row.id + '" onclick="qrcodeimg(' + row.id + ',this)"><span id="span-qrcode-' + row.id + '">点击查看二维码</span></div>';
                }, searchable: false, orderable: false
            },
            {
                data: null, render: function (data, type, row) {
                    return row.c_tool_id === 47 ? 8000 : 300;
                }, searchable: false, orderable: false
            },
            {data: 'b_paid_at'},
            {
                data: 'b_paid_status', render: function (data, type, row) {
                    // console.log(data)
                    return data != 1 ? '未支付' : '已支付';
                }, searchable: false, orderable: false
            },
            {data: 'b_paid_num', orderable: false},
            {
                data: null, render: function (data, type, row) {
                    return '';
                }, searchable: false, orderable: false
            },
            {data: 'b_client_contact'},
            {data: 'b_client_tel'}
        ]
    });
    table.on('draw', function (a, b) {
        params = b.oAjaxData;
    })
    $.Huitotop();

    function qrcodeimg(id, e) {
        let divid = $(e).attr('id');
        let key = $(e).attr('key');
        let ishide = $(e).hasClass('qrcodehide');
        let spanid = 'span-qrcode-' + id;
        if (!ishide) {
            let url = 'http://' + window.location.host + '/viewRes?id=' + id + '&key=' + key;
            $(e).addClass('qrcodehide');
            var qrcode = new QRCode(divid, {
                width: 70,
                height: 70
            });
            $('#' + spanid).text('点击隐藏二维码');
            qrcode.makeCode(url);
        } else {
            let str = '<span id="' + spanid + '">点击查看二维码</span>';
            $(e).html(str);
            $(e).removeClass('qrcodehide');
        }
    }

    function download_excel(key, e) {
        let href = 'exportList/' + key+'?'+$('#exportform').serialize();
        if (key === 1) {
            let pageinfo = table.page.info();
            if(pageinfo.recordsDisplay === 0){
                layer.alert('没有数据！');
                return false;
            }
            if (typeof params === 'object') {
                params = JSON.stringify(params);
            }
            $(e).attr('href', href + '&params=' + params);
        } else {
            $(e).attr('href', href);
        }
    }

    function searchDate() {
        let datemin = $.trim($('#datemin').val()), datemax = $.trim($('#datemax').val());
        if(datemin === '' && datemax === ''){
            changedate();
        }
        table.ajax.reload();
    }
    function changedate() {
        let year = $.trim($('#year').val()), month = $.trim($('#month').val()), week = $.trim($('#week').val()), date = new Date();
        //年月周都不为空
        if(year || month || week){
            year = year ? year : date.getFullYear(); //年
            month = month ? month : date.getMonth()+1; //月
            //计算日期
            let startday = week ? (week-1)*7+1 : '01',lastDay= new Date(year,month,0).getDate();
            if(startday > lastDay){
                layer.msg('该周次不存在，请重新选择');
                return false;
            }
            comlastDay = startday+6 ;
            endday =  week ? (comlastDay > lastDay ? lastDay : comlastDay) : lastDay;
            $('#datemin').val(year + '-' + month + '-' + startday);
            $('#datemax').val(year + '-' + month + '-' + endday);
        }
    }
    $("#emptyw").click(function () {
       $('#year').val('');
       $('#month').val('');
       $('#week').val('');
    })

</script>
</body>
</html>
